package com.example.blog.dao;

import com.example.blog.pojo.type;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Mapper
public interface typeRepository {

    @Select("select * from blog.type where id = #{id}")
    public type findById(Integer id);

    @Select("select * from blog.type where name = #{name}")
    public type findByName(String name);

    @Insert("insert into blog.type (id,name) values (#{id},#{name})")
    void save(type type);

    @Select("select * from blog.type")
    Page<type> findAll();

    @Delete("delete from blog.type where id = #{id}")
    void delete(Integer id);

    @Select("select count(*) from blog.type")
    Integer count();

    @Update("update blog.type set name=#{name} where id=#{id}")
    void update(Integer id, String name);

    @Select("SELECT type_id ,type.`name`, count(type_id) as'typeCount' FROM blog,type WHERE blog.type_id = type.id GROUP BY type_id")
    public Page<type> find();

}
